#include "enroll.h"
#include "ui_enroll.h"
#include "login.h"
#include <QMessageBox>
#include <QWidget>
#include <QMovie>
#include "client_connet.h"
#include "interface_control.h"

Enroll::Enroll(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Enroll)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::SplashScreen|Qt::WindowStaysOnTopHint|Qt::FramelessWindowHint);


    QMovie *mv=new QMovie(":/res/111.png"); //创建一个图
        ui->label->setMovie(mv); //将图插入标签
        mv->start(); //启动图
        ui->label->setScaledContents(true); //让图自适应标签大小

    QMovie *Mv=new QMovie(":/res/012.png");
        ui->label_2->setMovie(Mv);
        Mv->start();
        ui->label_2->setScaledContents(true);

}

Enroll::~Enroll()
{
    delete ui;
}

void Enroll::on_enroll_clicked()
{

    if(ui->lineEdit->text() == NULL || ui->lineEdit_2->text() == NULL )
    {
        QMessageBox::information(this,"提示","账户密码不能为空！！",QMessageBox::Yes);
    }
    else
    {
        QJsonObject js ;
        js.insert("cmd",0);
        js.insert("nickname",ui->lineEdit->text());
        js.insert("password",ui->lineEdit_2->text());

        //发送信息
        Client_connet::Get_Connet()->set_obj(js);
        Client_connet::Get_Connet()->SendServer();
    }
}


void Enroll::on_return_2_clicked()
{
    this->close();
    this->hide();
    Interface_Control::getControlptr()->showLogin();

}

void Enroll::mousePressEvent(QMouseEvent *event)
{
    isPressedWidget = true; // 当前鼠标按下的即是QWidget而非界面上布局的其它控件
    last = event->globalPos();
}

void Enroll::mouseMoveEvent(QMouseEvent *event)
{
    if (isPressedWidget)
        {
            int dx = event->globalX() - last.x();
            int dy = event->globalY() - last.y();
            last = event->globalPos();
            move(x()+dx, y()+dy);
        }
}

void Enroll::mouseReleaseEvent(QMouseEvent *event)
{
    int dx = event->globalX() - last.x();
    int dy = event->globalY() - last.y();
    move(x()+dx, y()+dy);
    isPressedWidget = false; // 鼠标松开时，置为false
}

void Enroll::enrollment_tips(int a)
{
    if(a == -1)
    {
        QMessageBox::information(this,"提示","注册失败！！",QMessageBox::Yes);
    }
    else
    {
        QMessageBox::information(this,"提示","注册成功！！",QMessageBox::Yes);
    }
}

